<%@ page language="java" contentType="text/html; charset=UTF-8"
	pageEncoding="UTF-8"%>
<%@taglib prefix="c" uri="http://java.sun.com/jsp/jstl/core"%>
<%@taglib prefix="s" uri="http://www.springframework.org/tags"%>
<!DOCTYPE html>
<html>
<head>
<script type="text/javascript" src="${pageContext.request.contextPath}/js/jquery.min.js"></script>
<meta charset="UTF-8">
<title><s:message code="EMPLOYEE.LIST"></s:message></title>
</head>
<body>
<input type="button" value="添加" id="add">
	<table>
		<tr>
			<td>id</td>
			<td><s:message code="EMPLOYEE.LASTNAME"></s:message> </td>
			<td><s:message code="EMPLOYEE.EMAIL"></s:message></td>
			<td><s:message code="EMPLOYEE.GENDER"></s:message></td>
			<td><s:message code="SYS.OPERATE"></s:message></td>
		</tr>
		<c:forEach var="item" items="${pages.list}">
			<tr class="row">
				<td>${item.id}</td>
				<td>${item.lastName}</td>
				<td>${item.email}</td>
				<td>${item.gender}</td>
				<td > <input type="button" value="<s:message code='SYS.EDIT'></s:message> "  class="editRow">
				<input type="hidden" value="${item.id}"/>
				</td>
				<td > <input type="button" value="<s:message code='SYS.DETAIL'></s:message> "  class="detailRow">
				<input type="hidden" value="${item.id}"/>
				</td>
				
			</tr>
		</c:forEach>
	</table>
	<p>
		<c:if test="${pages.hasPreviousPage}">
			<input type="button" class="page" value="前一页"/>
			<input type="hidden" value="${pages.prePage}">
		</c:if>
		<c:forEach var="item" items="${pages.navigatepageNums}">
			<c:if test="${item==pages.pageNum}">
				<input type="button" class="page" style="color: red" value="${item}">
			</c:if>
			<c:if test="${item!=pages.pageNum}">
				<input type="button" class="page" value="${item}">
			</c:if>
			<input type="hidden" value="${item}">
		</c:forEach>
		<c:if test="${pages.hasNextPage}">
			<input type="button" class="page" value="下一页"/>
			<input type="hidden" value="${pages.nextPage}">
		</c:if>
		<input type="hidden" id="pageNum" value="${pages.pageNum}"> <input
			type="hidden" id="pageSize" value="${pages.pageSize}">
	</p>
</body>
<script>
	$(function() {
		$(".page").each(function() {
							$(this).click(function() {
												var pageNum = $(this).next().val();
												var pageSize = 5;
												window.location = "${pageContext.request.contextPath}/emp/list?pageNum="
														+ pageNum
														+ "&pageSize="
														+ pageSize;
											})
						});
		$("#add").click(function(){
			window.location = "${pageContext.request.contextPath}/emp/add"
		})
		$(".editRow").each(function(){
			$(this).click(function(){
				var id = $(this).next().val();
				window.location = "edit/"+id
			})
		})
		$(".detailRow").each(function(){
			$(this).click(function(){
				var id = $(this).next().val();
				$.get("${pageContext.request.contextPath }/emp/detail/"+id,function(data){
					if(data.code == 200){
						data = data.context.data;
						alert("姓名："+data.lastName+",邮箱："+data.email+",性别："+data.gender);
					}
					
				})
				
			})
		})
		
	})
</script>
</html>